package com.example.cms.service.Impl;

import com.example.cms.dao.ConsultantDao;
import com.example.cms.entity.Consultant;
import com.example.cms.pojo.FileExport;
import com.example.cms.pojo.QueryPage;
import com.example.cms.service.ConsultantService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

@Service("ConsultantService")
@Transactional
public class ConsultantServiceImple implements ConsultantService {

    @Autowired
    private ConsultantDao consultantDao;

    @Override
    public Consultant getConsultantAndCourses(Integer consultantId) {
        return consultantDao.selectConAndCate(consultantId);
    }

    @Override
    public List<Consultant> getConAndCou(QueryPage queryPage,Consultant consultant) {
        queryPage.setCurr_page((queryPage.getCurr_page()-1)*queryPage.getPageSize());
        return consultantDao.selectAllConsultant(queryPage);
    }

    @Override
    public Integer getNum() {
        return consultantDao.getNum();
    }

    @Override
    public FileExport getCon() {
       List<Consultant> consultants= consultantDao.getAll();
        SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd");
        FileExport fileExport =new FileExport();
        List<FileExport> fileExports =new ArrayList<FileExport>();
        String [] state ={"未激活","激活"};
        String [] sexs ={"男","女"};
        //添加表名
        fileExport.setName("顾问导出数据");
        //添加表头
        List<String> titles = new ArrayList();
        titles.add("顾问名称");
        titles.add("顾问序号");
        titles.add("顾问电话");
        titles.add("顾问地址");
        titles.add("顾问级别");
        titles.add("顾问金额");
        titles.add("顾问性别");
        fileExport.setTitles(titles);
        //添加数据
        List<List<Object>> rows = new ArrayList();
        List<Object> c ;
        for (int i=0; i< consultants.size();i++){
            c=new ArrayList<Object>();
            c.add(consultants.get(i).getConsultantName());
            c.add(consultants.get(i).getConsultantId());
            c.add(consultants.get(i).getConsultantPhone());
            c.add(consultants.get(i).getConsultantAddress());
            c.add(consultants.get(i).getConsultantLv());
            c.add(consultants.get(i).getConsultantMoney());
            c.add(sexs[consultants.get(i).getConsultantSex()]);
            rows.add(c);
        }
        fileExport.setRows(rows);
        return fileExport;

    }

    @Override
    public Integer removeConsultant(Integer consultantId) {//删除
        return consultantDao.deleteConsultant(consultantId);
    }

    @Override
    public Integer eidtConsultant(Consultant consultant) {//修改
        return consultantDao.updateConsultant(consultant);
    }

    @Override
    public Integer addtConsultant(Consultant consultant) {//增加
        return consultantDao.insertConsultant(consultant);
    }
}
